package edu.sctu.wangfuxin.day20150527;

/**
 * Created by user06 on 2015/5/27.
 */
public class Student {

    public String name;
    public double code;
    public int age;
    public String sex;
    public int number;
    public CampusCard campusCard;

    public Student(String name,int age, String sex, int number,CampusCard campusCard){
        this.age = age;
        this.name =name;
        this.sex = sex;
        this.number = number;
        this.campusCard = campusCard;

    }

    public String getName() {return name;};
    public double getCode() {return code;};
    public String getSex() {return sex;};
    public int getNumber() {return number;};
    public int getAge() {return age;};

    /**
     *
     * @param windows
     * @return
     */
    public Window selectWindow(Window[] windows,Dish dish){
        Window win = null;
        int min1 = windows[0].queuelength < windows[1].queuelength? windows[0].queuelength : windows[1].queuelength;
        int min = windows[2].queuelength < min1 ? windows[2].queuelength : min1;
        for (int i = 0; i < windows.length; i++) {
            for (int j = 0; j < windows[i].dishs.length; j++) {
                if (windows[i].dishs[j] == dish && min == windows[i].queuelength) {
                    win = windows[i];
                }
            }

        }
        return win;
    }

    /**
     * 选择菜品
      * @param dish 所选择的菜品
     * @return 所选择的菜品
     */

    public Dish selectDish(Dish dish){
        return dish;

    }

    /**
     *选择是否需要米饭
     * @param weight 所需要的分量
     * @param window 学生所选择的窗口
     * @return 米饭的费用
     */

    public double needRice(double weight,Window window){

        return weight * window.ricePeice;
    }

    /**
     * 刷卡消费
     * @param dish 学生选择的菜
     * @param campusCard 学生的校园卡
     * @param weight 学生所打饭的分量
     * @param window 学生所选择的窗口
     * @return 刷卡后卡上的余额
     */
    public double consume(Dish dish,Dish dish1,CampusCard campusCard,double weight,Window window){
//        Dish dish1 = selectDish(dish);
        double ricePrice = needRice(weight, window);
        if (dish.price +dish1.price + ricePrice <campusCard.balance) {
            System.out.println("您卡上余额不足，请充值！");
        }
        System.out.println("您已消费成功！消费"+dish.price +dish1.price + ricePrice+"元");
        return campusCard.balance = campusCard.balance - dish.price -dish1.price - ricePrice;
    }

}
